<%@page import="com.interfaces.TravelAgentController"%>
<%@ page import="com.interfaces.UserController" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Starter</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
        String path = request.getContextPath();
        path = "/".equals(path)?"":path;
        request.setAttribute("path", path);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css">
    <!-- Select2 -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/select2/select2.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="${path}/css/common.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="${path}/js/json2.js"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body >
<div class="container">

    <div class="box box-primary">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="loginName">用户名</label>
                        <input type="text" class="form-control" id="loginName" placeholder="用户名" validata="len" errormsg="" emptyerrormsg="用户名不能为空" empty="false" limitLength="50">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="pwd">密码</label>
                        <input type="password" class="form-control" id="pwd1" placeholder="密码" validata="len" errormsg="" emptyerrormsg="密码不能为空" empty="false" limitLength="50">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="password2">确认密码</label>
                        <input type="password" class="form-control" id="pwd" placeholder="再次输入密码"  validata="len" errormsg="确认密码不能为空">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="travelId">所属旅行社</label>
                        <select  class="form-control" id="travelAgentId"  validata="len" errormsg="所属旅行社不能为空">
                    	</select>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="travelAgentId">姓名</label>
                        <input type="text" class="form-control" id="travelAgentId" placeholder="姓名" validata="len" errormsg="" emptyerrormsg="姓名不能为空" empty="false" limitLength="50">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="state">状态</label>
                        <select id="state" class="form-control">
                        	<option value="#">==请选择==</option>
                            <option value="0">禁用</option>
                            <option value="1">活动</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="remark">备注</label>
                        <input type="text" class="form-control" id="remark" placeholder="备注" validata="len" errormsg="" empty="true" limitLength="500">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <button type="submit" class="btn btn-primary" id="btnAdd">保 存</button>
                </div>
            </div>
        </div>
    </div>
    <!-- /.box -->
</div>

<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/public/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Select2 -->
<script src="${path}/public/adminlte/plugins/select2/select2.full.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<script src="${path}/js/validata.js"></script>
<script src="${path}/js/sysDict.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
function formatRepo (repo) {
      if (repo.loading) {return repo.text;}
      return repo.text+"("+repo.id+")";
    }
    function formatRepoSelection (repo) {
    return repo.text ; 
    }
$("#travelAgentId").select2({
	language: "zh-CN",
	width: "100%",
  	ajax: {
        url: "${path}<%=TravelAgentController.URL_SEARCH%>",
        dataType: 'json',
        delay: 1000,
        type:"post",
        data: function (params) {
        params.page = params.page || 1;
          return {
            travelAgentName: params.term, // 关键字
            curPage: params.page, 
            pageSize: 10,
	        singlePage: 0          
          };
        },
        processResults: function (data, params) {
          params.page = params.page || 1;
          return {
            results: data.items,//items:数据 data.total_count:总记录数,items中，字段id为option中的value值，
            pagination: {
              more: (params.page * 10) < data.total_count //页数*每页记录数小于总记录数时，可记录下拉
            }
          };
        },
        cache: true
      },
      escapeMarkup: function (markup) { return markup; },
      minimumInputLength: 0,
      templateResult: formatRepo,
      templateSelection: formatRepoSelection
	});
    $(function () {
		$("#btnAdd").click(function () {
    	if(!checkSubmit()) return false;
        var loginName = $("#loginName").val();
        if(loginName==null||loginName==""){
        	alert("用户名没有填写!!!")
        	return false;
        }
        var password = $("#pwd").val();
        if(password==null||password==""){
        	alert("密码没有填写!!!")
        	return false;
        }
        var travelAgentId = $("#travelAgentId").val();
        if(travelAgentId==null||travelAgentId==""){
        	alert("所属旅行社没有填写!!!")
        	return false;
        }
        var state = $("#state").val();
        if(state==null||state==""){
        	alert("状态没有填写!!!")
        	return false;
        }
        var remark = $("#remark").val();
        $.ajax({
            url:"${path}<%=UserController.URL_ADD%>?&"+Math.random(),
            type:"post",
            data:{loginName:loginName,password:password,travelAgentId:travelAgentId,state:state,remark:remark},
            success:function(result){
                var re = JSON.parse(result);
                if(re.returnCode=="0"){
                	alert("新增用户成功！");
                	var url = window.location.search;
					var arr=url.split('&');
					//调用main页面刷新
					parent.parent.$('#s_'+arr[arr.length-1]).contents().find("#btnSearch").click();
					var roleID=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
					var id=re.obj;
					parent.addTab({id: roleID, title: "用户角色设置", url:"${path}<%=UserController.URL_GOTO_ADD_UPDATE_ROLE_PAGE%>?id="+id+"&"+roleID+"&"+arr[arr.length-1], close: false});
					window.location.href="${path}<%=UserController.URL_GOTO_ADD_UPDATE_PAGE%>?id="+id+"&"+arr[arr.length-2]+"&"+arr[arr.length-1];
					//关闭当前tab
                }else{
                    alert(re.msg);
                }
            },
            error:function(request) {      // 设置表单提交出错
                alert(request);  //登录错误提示信息
            }
        });

        return false;
     });

    });
</script>
</body>
</html>
